package com.example.base.validation.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author X.I.O
 * @title: ValidatedUtils
 * @projectName springboot
 * @description: TODO
 * @date 2021/10/29 15:24
 */
public class ValidatedUtils {


    private static final Pattern PATTERN_MAIL = Pattern.compile("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$");
    /**
     * 校验手机号码格式是否正确
     * @param mobile  需要校验的手机号码
     * @return  boolean
     */
    public static boolean isMobile(String mobile) {
        String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
        if (mobile.length() != 11) {
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(mobile);
            boolean isMatch = m.matches();
            if (isMatch) {
                return true;
            } else {
                return false;
            }
        }
    }

    /**
     * 校验邮箱是否存在
     * @param mail 邮箱
     * @return
     */
    public static boolean isMail(String mail){
        Matcher matcher = PATTERN_MAIL.matcher(mail);
        return matcher.matches();
    }

    public static boolean isInteger(String str){
        String regex="^[0-9]*$";
        if(str==null || "".equals(str)){
            return false;
        }
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean isMatch = m.matches();
        if (isMatch) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isClass(String str){
        if (str == null || "".equals(str)) {
            return false;
        }
        try {
            Class<?> clsClass=Class.forName(str);
            System.out.println(str+"存在反射类");
            return true;
        }catch (ClassNotFoundException e) {
            return false;
        }
    }
}
